import { Button, Table, Descriptions, Radio, Input } from 'antd';
import React, { useState } from 'react';
import { useEffect } from 'react';
import { useSearchParams } from 'react-router-dom';
import request from '../../../utils/request'


const Add = () => {
  const [params, setParams] = useSearchParams()
  let userInfo = localStorage.getItem('userInfo')
  try {
    userInfo = JSON.parse(userInfo) || {}
  } catch (err) {
    userInfo = {}
  }
  // console.log(params.get('id'));
  const id = params.get('id')
  const [ansData, setAnsData] = useState([])
  const [queData, setqueData] = useState('')
  const [input, setInput] = useState('')
  const { TextArea } = Input;
  const onChange = (e) => {
    console.log('Change:', e.target.value);
    setInput(e.target.value)

  };
  console.log('Input', input);
  console.log('userInfo', userInfo);
  const onClick = () => {
    request.post('/answer', {


      iqid: id,
      content: input,
      userid: userInfo._id

    })
  };

  const iqData = async () => {
    const qdata = await request.get('/iq/' + id)

    setqueData(qdata.data.data.question)

    console.log(qdata);
  }

  const answerData = async () => {
    const andata = await request.get('/answer', {
      params: {
        iqid: id
      }
    })

    setAnsData(andata.data.data.result)
    // console.log('b',andata.data.data.result);
    // console.log('a',andata);
  }

  useEffect(() => {
    answerData()
    iqData()
  }, [])










  return (
    <div>
      <h2>面试题：{queData}</h2>
      <br />
      <br />
      <TextArea size="large" showCount maxLength={1000} onChange={onChange} />
      <br />

      <Button type="primary" onClick={onClick} size={13}>
        提交
      </Button>
    </div>
  );
};

export default Add;